package com.haojin.java1;

import org.junit.Test;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
import java.util.Comparator;

/**
 * @author .29.
 * @create 2022-04-20 21:18
 */
/*
Lambda表达式地使用举例
 */
public class LambdaTest {
    @Test
    public void test1(){
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                System.out.println("我爱洗澡皮肤好好");
            }
        };
        r1.run();

        System.out.println("******************");
        //Lambda表达式
        Runnable r2 = () -> System.out.println("我爱洗澡皮肤好好");

        r2.run();
    }
    @Test
    public void test2(){
        Comparator<Integer> com1 = new Comparator<Integer>(){

            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
        System.out.println(com1.compare(3, 3));

        System.out.println("******************");
        Comparator<Integer> com2 =(o1,o2)->Integer.compare(o1,o2);
        System.out.println(com2.compare(3, 4));
        System.out.println("******************");
        Comparator<Integer> com3 =Integer :: compare;
        System.out.println(com3.compare(5, 4));

    }
}
